﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class webadmin_pages_ajax_nhantin : System.Web.UI.Page
{
    public bool bGui;
    private Common comm = new Common();
    public DataRow dtr;
    public DataTable dtt;
    public bool guithanhcong;
    public string idGui = "";
    public string idNhan = "";
    public string kieugui = "";

    protected void btnOk_Click(object sender, EventArgs e)
    {
        string[] strArray = this.idNhan.Split(new char[] { ';' });
        for (int i = 0; i < (strArray.Length - 1); i++)
        {
            string tinnhanId = comm.GenerateID() + i.ToString();
            string sqlString = "Insert HeThong_tin_nhan (id,tieu_de,noi_dung,nguoi_gui,nguoi_nhan,kieu_nguoi_gui) VALUES ('"+ tinnhanId + "', N'" + this.txtTieuDe.Text + "',N'" + this.txtNoiDung.Text + "','" + this.idGui + "','" + strArray[i].ToString() + "'," + this.kieugui + ")";
            if (this.comm.execNoneQuery(sqlString) > 0)
            {
                this.guithanhcong = true;
            }
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(base.Request.QueryString["idgui"]))
        {
            this.idGui = this.comm.TextFormat(base.Request.QueryString["idgui"]).Trim();
        }
        if (!string.IsNullOrEmpty(base.Request.QueryString["idnhan"]))
        {
            this.idNhan = this.comm.TextFormat(base.Request.QueryString["idnhan"]).Trim();
        }
        if (!string.IsNullOrEmpty(base.Request.QueryString["type"]))
        {
            this.kieugui = this.comm.TextFormat(base.Request.QueryString["type"]).Trim();
        }
        if ((!base.IsPostBack && !string.IsNullOrEmpty(this.idNhan)) && (!string.IsNullOrEmpty(this.idGui) && !string.IsNullOrEmpty(this.kieugui)))
        {
            this.bGui = true;
            string[] strArray = this.idNhan.Split(new char[] { ';' });
            if (this.kieugui == "2")
            {
                this.txtTenNguoiGui.Text = (string)ConfigurationManager.AppSettings["centername"];
                for (int i = 0; i < (strArray.Length - 1); i++)
                {
                    this.txtTenNguoiNhan.Text = this.txtTenNguoiNhan.Text + this.comm.execScalar("select ten_doanh_nghiep from DoanhNghiep_doanh_nghiep where ma_doanh_nghiep='" + strArray[i].ToString() + "'") + "';";
                }
            }
            else if (this.kieugui == "3")
            {
                this.txtTenNguoiGui.Text = (string)ConfigurationManager.AppSettings["centername"];
                for (int j = 0; j < (strArray.Length - 1); j++)
                {
                    this.txtTenNguoiNhan.Text = this.txtTenNguoiNhan.Text + this.comm.execScalar("select ho_ten from ConNguoi_nguoi where ma_nguoi='" + strArray[j].ToString() + "'") + ";";
                }
            }
        }
    }
}
